package com.kedacom.ctsp.authz.access;

import com.kedacom.ctsp.authz.entity.Authentication;
import com.kedacom.ctsp.web.entity.CreatorNameRecordableBeanWithCode;
import com.kedacom.ctsp.web.entity.CreatorRecordableBeanWithCode;
import org.springframework.stereotype.Service;


/**
 * TODO 完成注释
 *
 * @author xuwei
 */
@Service
public class CreatorRecordableBeanHandler extends RecordableBeanHandlerAdaptor<CreatorRecordableBeanWithCode> {

    @Override
    public void handleSilently(CreatorRecordableBeanWithCode entity, Authentication auth) {
        entity.setCreateTimeNow();
        if (auth != null && auth.getUser() != null) {
            entity.setCreatorCode(auth.getUser().getUsername());
            if (entity instanceof CreatorNameRecordableBeanWithCode) {
                ((CreatorNameRecordableBeanWithCode) entity).setCreatorName(auth.getUser().getUsername());
            }
        }
    }
}
